package com.test.test.timerTask.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Configuration  
@Component // 此注解必加  
@EnableScheduling // 此注解必加    
/**
 * 使用注解调度任务
 * 下一步目标 动态调度任务
 * 
 */
public class AnnotationQuartzTask {
	
	//没三秒调度一次
	@Scheduled(fixedRate = 1000 * 3)
	public void reportCurrentTime() {
		System.out.println("Scheduling Tasks Examples: The time is now " + dateFormat().format(new Date()));
	}

	// 每1分钟执行一次
	@Scheduled(cron = "0 */1 *  * * * ")
	public void reportCurrentByCron() {
		System.out.println("Scheduling Tasks Examples By Cron: The time is now " + dateFormat().format(new Date()));
	}

	private SimpleDateFormat dateFormat() {
		return new SimpleDateFormat("HH:mm:ss");
	}
}
